# -*- coding: utf-8 -*-
"""
Created on Thu Aug  9 22:46:21 2018

@author: Hy
"""
import os
import multiprocessing
import json


def writetxt(m):
    model = __import__(m)
    model.main()


def main(l):
    pool = multiprocessing.Pool(processes=4)
    for x in l:
        if os.path.splitext(x)[1] == '.py' and os.path.splitext(x)[0] not in (
                'start', 'WriteData',):
            m = os.path.splitext(x)[0]
            pool.apply_async(writetxt, (m,))
    pool.close()
    pool.join()


def fb():
    with open('核财经深度文章.txt', encoding='utf-8') as f:
        line = f.readline()
        line = json.loads(line)
        data = line['ctime']
        if not data:
            return
    with open('config.txt', 'w', encoding='utf-8') as fd:
        fd.write(data)


if __name__ == '__main__':
    if os.path.exists('核财经深度文章.txt'):
        os.remove('核财经深度文章.txt')
    l = os.listdir()
    main(l)
    fb()
